package com.recharge.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.utils.JsonResult;
import com.entity.Customer;
import com.entity.Recharge;
import com.recharge.entity.JsonRecharge;
import com.recharge.entity.JsonRechargeCustomer;
import com.recharge.srevice.RechargeService;;

/**
 * @Title: RechargeController.java
 * @Package com.recharge.controller
 * @author 孙梦楠
 * @date 2017年8月24日 上午11:23:18
 * @version V1.0.0
 */
@RestController
@RequestMapping(value = "/recharge")
public class RechargeController {

	@Autowired
	private RechargeService rechargeservice;

	// 列表
	@RequestMapping(value = "/list_recharge_customer_total", method = RequestMethod.POST)
	public JsonResult<List<JsonRechargeCustomer>> list_recharge_customer_total(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie,
			@RequestBody Customer customer) {

		String customeraccount = customer.getCustomeraccount();
		String customername = customer.getCustomername();
		String customeraddress = customer.getCustomeraddress();

		return rechargeservice.list_recharge_customer(opeorgcookie, opetypecookie, customeraccount, customername,
				customeraddress,languagecookie,"总");
	}
	
	// 列表
		@RequestMapping(value = "/list_recharge_customer_child", method = RequestMethod.POST)
		public JsonResult<List<JsonRechargeCustomer>> list_recharge_customer_child(
				@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
				@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
				@CookieValue(value = "languagecookie", required = false) String languagecookie,
				@RequestBody Customer customer) {

			String customeraccount = customer.getCustomeraccount();
			String customername = customer.getCustomername();
			String customeraddress = customer.getCustomeraddress();

			return rechargeservice.list_recharge_customer(opeorgcookie, opetypecookie, customeraccount, customername,
					customeraddress,languagecookie,"分");
		}
	

	// 充值
	@RequestMapping(value = "/recharge", method = RequestMethod.POST)
	public JsonResult<Recharge> recharge(@RequestBody Recharge recharge,
			@CookieValue(value = "opecodecookie", required = false) String opecodecookie) {

		Integer customerid = recharge.getCustomerid();
		Double money = recharge.getMoney();

		return rechargeservice.recharge(customerid, opecodecookie, money);

	}

	// 充值历史记录
	@RequestMapping(value = "/recharge_history", method = RequestMethod.POST)
	public JsonResult<List<JsonRecharge>> recharge_history(@RequestBody Customer customer,
			@CookieValue(value = "languagecookie", required = false) String languagecookie)  {

		Integer customerid = customer.getCustomerid();
		
		JsonResult<List<JsonRecharge>> lists = rechargeservice.rechargehistory(customerid,languagecookie);
		return lists;

	}
	

	


}
